const fs = require('fs')
const { ncp } = require('ncp');

const copyFile = (source, destination) => {
    return new Promise((resolve, reject) => {
        ncp(source, destination, err => {
            if (err) return reject(err);
            resolve({ state: 'success' })
        })
    })
}

const removeDir = (path) => {
    let files = [];
    if (fs.existsSync(path)) {
        files = fs.readdirSync(path);
        files.forEach((file) => {
            let curPath = path + "/" + file;
            if (fs.statSync(curPath).isDirectory()) {
                removeDir(curPath); //递归删除文件夹
            } else {
                fs.unlinkSync(curPath); //删除文件
            }
        })
        fs.rmdirSync(path);
    }
}
module.exports = {
    copyFile,
    removeDir
}